﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Metadata.Entity;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using static T.FAS.Runtime.Metadata.Entity.DataModel.StateMachineRefSchemaEntity;

namespace T.FAS.Runtime.Action.SPI
{
    public class ActionRTPUtil
    {
        public static long GetTimeStamp(DateTime dTime)
        {
            var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            return (long)(dTime - startTime).TotalSeconds;
        }

        public static ActionMetaData ActionMetadataValid(IMetaDataContent metaData)
        {
            var action = metaData as ActionMetaData;
            if (action == null)
            {
                var type = metaData?.GetType();
                var errorMsg = ActionExecuteExceptionMsg.GetActionNotExistErrorMsg(metaData?.MetaDataCode);
                if (metaData != null)
                    errorMsg += $" 类型为：{type?.Name}, metaId:{metaData.MetaDataID},metaCode:{metaData.MetaDataCode}";
                throw new FasException(ActionExecuteExceptionCode.ActionExecuteEngineExecuteError, errorMsg);
            }
            return action;
        }
        public static void ActionMetadataRelatedCDOValid(string actionCode, CompositeDataObject cdo)
        {
            if (cdo == null)
            {
                throw new FasException(ActionExecuteExceptionCode.ActionExecuteEngineExecuteError, ActionExecuteExceptionMsg.GetActionRelatedCDONotExistsErrorMsg(actionCode));
            }

        }
    }
}